home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1288 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  4.9 KB

  1. Path: mujibur.inmind.com!usenet
  2. From: mfinney@inmind.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Hungarian notation
  5. Date: 10 Jan 1996 08:48:08 GMT
  6. Organization: In Mind, Inc.
  7. Message-ID: <4cvug8$5hh@mujibur.inmind.com>
  8. References: <cmanDK7x13.5KM@netcom.com> <verec-2712952049000001@ppp30.micronet.fr> <30E39BC0.3BAE@zeta.org.au> <verec-2912950003390001@ppp05.micronet.fr> <30E55183.52FF@zeta.org.au> <4c44dh$771@mujibur.inmind.com> <4c477m$ou4@macaw.cyberport.com> <4ccq2u$3e3@mujibur.inmind.com> <4cmblb$hj2@macaw.cyberport.com>
  9. Reply-To: mfinney@inmind.com
  10. NNTP-Posting-Host: finneyman.inmind.com
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <4cmblb$hj2@macaw.cyberport.com>, tkennedy@cyberport.com (Warren Young) writes:
  14. >Of course.  These were merely examples of well-known functions where
  15. >passing the new string would cause problems.  You asserted that the
  16. >semantics didn't change, and I just dashed off some examples that
  17. >disproved that.
  18.  
  19. You mistaketh me for someone else, sirrah!  The post you quoted
  20. was my FIRST post, so you couldn't have been replying to a previous
  21. message by me.
  22.  
  23. >printf() is kinda obsolete.  If you are dealing with wide character types
  24. >>you are almost certainly not going to be using printf().  
  25. >
  26. >Your example was converting an existing "standard" string into a wide
  27. >character string by prefixing it with L.  So, it's very likely that
  28. >the original program was using something that wanted regular strings,
  29. >and the change will probably stop it working from right.
  30.  
  31. Not at all.  Just because you are using "regular" strings does
  32. not mean that you are using printf() or any other function
  33. which does not have the approprite overloaded definitions.
  34. Although, it certainly MAY make things stop working.  But
  35. that is an issue of type dependence which should be addressed
  36. directly.
  37.  
  38. >Sure, you can do the compile-and-grep thing until it finally compiles,
  39. >but this method can fail you, because of the usages can be missed.
  40. >Between strong type checking, lack of vararg functions and careful
  41. >coding habits, you can be assured that the compiler will catch most of
  42. >the problems, but it's always those little things that the compiler
  43. >thought were copacetic that get you.
  44. >
  45. >If you're using HN, you will be _forced_ to visit every usage of that
  46. >variable.
  47.  
  48. The "grep and compile" approach -- or load ALL source files into
  49. your editor and perform a global, multi-buffer search will also
  50. visit all occurences.  If that is appropriate.  I don't need HN for
  51. that!
  52.  
  53. >If you care enough about types to be using a
  54. >well-considered HN variant (I'm not talking about that Petzoldian
  55. >alphabet hash), you'll probably take the opportunity to make sure that
  56. >the semantics are still OK.  I know of no better way of encouraging
  57. >this than HN.
  58.  
  59. I would disagree here.
  60.  
  61. >I agree, and if this is heeded religiously, it completely solves type
  62. >compatibility problems for C++ houses.  In other, less perfect
  63. >environments, such as C-only houses and those where you can't count on
  64. >everyone to follow the rules, HN is useful.
  65.  
  66. Since when is C any less type safe than C++?  I don't know about
  67. you, but I haven't seen a K&R type C program in years and years.
  68. If you use ANSI C with function prototypes then you have most of
  69. the type safety of C++.  The primary except being the ability to
  70. convert a void pointer to any other pointer without an explicit
  71. type cast.
  72.  
  73. >HN also has another
  74. >mission, and that is to encourage programmers to consider semantic
  75. >issues more carefully, especially in cases where the code mixes types
  76. >and yet compiles without warning.  Your rule does nothing in this
  77. >regard.
  78.  
  79. I expect to mix types and have clean compiles!  Anywhere I mix
  80. types I better have the appropriate type compatabilities.
  81.  
  82. >The only excuse I can think of for not having constant folding turned
  83. >on is if your code is taking and using the address of a constant.  If
  84. >you're doing that, though, you have no sense of style anyway.
  85. >(Whether by your choice or Fate's, the result is the same.)
  86.  
  87. I don't know about you, but not only do I turn type folding on, but I
  88. also force as many literals as possible into system read-only memory.
  89. When "const" was added to the language, it was a big mistake to
  90. allow literals to have a type which was not "const".  Sure, it would
  91. have broken a bit of code -- but that would have been minimized by
  92. supplying the appropriate variants of the library functions.
  93.  
  94. But "using the address of a constant" as bad style.  This is
  95. mandatory for string constants which ARE an address, and
  96. for other literals anytime you have to pass something by
  97. reference the address will be taken (implicitly, at least).
  98.  
  99. >It goes away with inline functions, too, becase you're likely to be
  100. >using conditional compilation to switch the various versions of the
  101. >inline wrapper in and out.  _I_ would be, anyway....
  102.  
  103. And, in many cases inline functions are the right approach.  But
  104. not necessarily the only approach or the best approach.
  105.  
  106.  
  107. Michael Lee Finney
  108.  
  109.